<template>
  <div class="edit-div">
    <el-steps :space="400" :active="1" finish-status="success">
      <el-step title="实验信息"></el-step>
      <el-step title="实验配置"></el-step>
      <el-step title="实验详情"></el-step>
    </el-steps>
    <div class="form">
      <div class="demo-input-suffix">
        <span class="form-input-label">实验名称：</span>
        <el-input class="long-input" v-model="data.experiment_name" placeholder="请输入实验名称"></el-input>
      </div>
      <div class="demo-input-suffix">
        <span class="form-input-label"><i class="el-icon-star-on"></i>付费：</span>
        <el-radio v-model="data.type" :label="2">免费</el-radio>
<!--        <el-radio v-model="data.type" :label="3">付费</el-radio>
        <el-input type="number" v-model="data.price" placeholder="请输入课程价格">
          <i class="el-input__icon" slot="prefix"> ￥ </i>
        </el-input> 元-->
      </div>
      <div class="demo-input-suffix">
        <span class="form-input-label">实验时长：</span>
        <el-input class="long-input" type="number" min="1" max="300" v-model="data.duration" placeholder="请输入实验时长"></el-input>分钟
      </div>
      <div class="submit-bar">
        <el-button type="primary" @click="onSubmit">下一步</el-button>
        <el-button @click="onCancel">取 消</el-button>
      </div>
    </div>
  </div>
</template>
<script>
import { experimentModel } from "@/api/models";
import { Message } from "element-ui";
import editorMixin from '@/mixins/editorMixin.js';
export default {
  mixins: [editorMixin],
  data() {
    return {
      data: {
        id: null,
        experiment_name: null,
        duration: null,
        type: 2
      }
    };
  },
  mounted() {
    if(this.$route.params.id) {
      experimentModel.item(this.$route.params.id, (res) => {
        this.data = res.data;
        this.editHtml = Boolean(res.data.editor)
      });
    }
  },
  methods: {
    getItem() {
      experimentModel.item(this.id, (res) => {
        this.data = res.data;
      });
    },
    onCancel() {
      this.$router.go(-1);
    },
    onSubmit() {
      let d = this.data;
      if (
        !d.experiment_name ||
        !d.duration ||
        !d.type
      ) {
        return Message.warning("请填完整信息");
      }
      let action;
      if (d.id) {
        action = experimentModel.update;
      } else {
        action = experimentModel.create;
      }
      action( d, (res) => {
          Message.success(res.message);
          this.$router.push('/env/set/' + res.data.id)
        }, (err) => {
          // Message.warning(err.message);
        }
      );
    }
  }
};
</script>
<style scoped lang="scss">
.form{
  text-align: left;
  margin-top: 50px;
}
.el-textarea {
  margin-left: 20px;
  width: 80%;
}
.custom-tree-node {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 14px;
  padding-right: 8px;
}
.el-tree-div {
  width: 50%;
  margin-left: 100px;
  border: 1px solid #cccccc;
  padding: 20px;
}
.tree-input > input {
  border: none;
  background: rgba(0, 0, 0, 0);
}
.link-konwledge{
  padding: 5px 15px;
  border: 1px solid #DCDFE6;
  margin-left: 20px; cursor: pointer;
}
.submit-bar{
  margin-top: 120px;
}
</style>